package sort;

/**
 * @Author Zhouchb
 * @Create 2021-10-2021/10/26 :12:59
 * @Description
 */
public class ComparableTest {
    public static void main(String[] args) {
        Man lindong = new Man(24, "林动");
        Man xiaoyan = new Man(26, "萧炎");
        int i = lindong.compareTo(xiaoyan);
        System.out.println(i);
    }

}
class Man implements Comparable<Man>{
        int age;
        String name;

    public Man(int age, String name) {
        this.age = age;
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public int compareTo(Man o) {
        if(o instanceof Man){
            if (o.age>this.age){
                return -1;
            }
            return 1;
        }
        return 0;
    }
}